/* 
 * Copyright 2011 kOSMik.
 * This file is part of kOSMik.
 * 
 * kOSMik is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * kOSMik is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with kOSMik.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * kOSMik:
 * Open Street Map - Editor.
 * http://code.google.com/p/swp-dv-ws2010-osm-2/
 */

package de.fuberlin.kosmik.gui.view.adapter;

import java.util.List;

import android.app.Activity;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import de.fuberlin.kosmik.data.osmt.OsmtData;
import de.fuberlin.kosmik.data.osmt.OsmtDataFactory;
import de.fuberlin.kosmik.data.osmt.OsmtKeyRecord;
import de.fuberlin.kosmik.gui.activity.TagEditingActivity;

/**
 * Acts as a bridge between (AutoCompleteTextView) edtKeyView in
 * TagEditingActivity and the underlying data for that view.
 * 
 * Fill the auto-complete list with key names of all known tag-keys
 * 
 * @author Johannes
 * @see AutoCompleteTextView
 * @see TagEditingActivity
 * 
 */
public class EditKeyAdapter extends ArrayAdapter<String> {

	private Activity activity;

	/**
	 * Constructor set the activity and fill the list with tags.
	 * 
	 * @param activity calling activity
	 */
	public EditKeyAdapter(final Activity activity) {
		super(activity, android.R.layout.simple_dropdown_item_1line);
		this.activity = activity;

		fillList();
	}

	/**
	 * Inflate all known key names.
	 */
	private void fillList() {
		// get data source
		OsmtData osmtData = OsmtDataFactory.createOsmtData(activity);
		final List<OsmtKeyRecord> keys = osmtData.fetchAllKeys();
		for (OsmtKeyRecord key : keys) {
			this.add(key.osmName);
		}
	}
}
